package edu.pku.sei.transformation.editor.views.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class HexagonFigure extends Figure {
	private Color foregroundColor = ColorConstants.black;
	private Color backgroundColor = ColorConstants.white;
	private Label name = new Label("test");

	public HexagonFigure() {
		ToolbarLayout layout = new ToolbarLayout();
		setLayoutManager(layout);
		setBackgroundColor(this.backgroundColor);
		this.add(name);
	}

	protected void paintFigure(Graphics graphics) {
		graphics.pushState();

		// graphics.fillGradient(getBounds(), true);
		Rectangle rect = getBounds().getCopy();
		graphics.translate(getLocation());
		int width = rect.width;
		int height = rect.height;
		int cornerSize = 5;
		// name.setLocation(new Point(0,0));
		// fill the note
		PointList outline = new PointList();
		outline.addPoint(0, height / 2);
		outline.addPoint(width / 4, 0);
		outline.addPoint(3 * width / 4, 0);
		outline.addPoint(width, height / 2);
		outline.addPoint(3 * width / 4, height);
		outline.addPoint(width / 4, height);

		graphics.setBackgroundColor(this.getBackgroundColor());
		graphics.setForegroundColor(this.getForegroundColor());
		graphics.setLineWidth(2);
		// graphics.fillPolygon(outline);
		graphics.drawPolygon(outline);
		// graphics.drawPolyline(outline);

		graphics.translate(getLocation().getNegated());
		graphics.popState();
	}
}
